import curses

background = curses.COLOR_BLACK
extras = {
"bold":curses.A_BOLD,
"blink":curses.A_BLINK,
"dim":curses.A_DIM,
"normal":curses.A_NORMAL,
"standout":curses.A_STANDOUT,
"reverse":curses.A_REVERSE}

colors = {
"red":curses.COLOR_RED,
"blue":curses.COLOR_BLUE,
"green":curses.COLOR_GREEN,
"cyan":curses.COLOR_CYAN,
"magenta":curses.COLOR_MAGENTA,
"white":curses.COLOR_WHITE,
"black":curses.COLOR_BLACK,
"yellow":curses.COLOR_YELLOW,
"background":background}


def setup_colors():
    curses.start_color()
    curses.use_default_colors()
    x = 0
    for fg in xrange(curses.COLORS):
        for bg in xrange(curses.COLORS):
            curses.init_pair(x,fg,bg)
            x += 1

def get_pair(fg,bg):
    return curses.color_pair( (fg*8) + bg)

def make_attr(color_desc):
    mods,filler,color_desc = color_desc.rpartition(":")
    if mods:
        mods = mods.split('|')
    if color_desc.count("/") == 0:
        fg = color_desc
        bg = "background"
    else:
        fg,bg = color_desc.split('/')
    colorpair = get_pair(colors[fg],colors[bg])
    for m in mods:
        colorpair += extras[m]
    return colorpair


def test(stdscr):
    setup_colors()

    color = make_attr("bold:red/blue")
    stdscr.addstr(1,1,str(color),color)
    color = make_attr("red/blue")
    stdscr.addstr(2,1,str(color),color)
    color = make_attr("normal:red/blue")
    stdscr.addstr(3,1,"Hellow World",color)
    stdscr.refresh()
    while 1: pass

if __name__ == "__main__":
    from curses import wrapper
    try:
        wrapper(test)
    except:
        pass
    